use container_core::{
    scheduler::simple_scheduler,
    workflow::{SimpleWorkflowEngine, WorkflowDocumentJsonReader},
};
use model_graph_types::{
    builder::configure::{
        DomainConfigureOptionBuilder, SchedulerConfigureOptionBuilder, ServerConfigureOptionBuilder,
    },
    container::{
        sheduler::Scheduler,
        workflow::{
            WorkflowDocumentReadeOptions, WorkflowDocumentReader, WorkflowEngine,
            WorkflowEngineCompileOptions, WorkflowEngineRunOptions,
        },
    },
    database::{ConnectorProtocol, DataSource as DatabaseDataSource, DatabaseType},
    modeling::{
        scheduler::{
            SchedulerTaskBuilder, SchedulerTaskContentType, SchedulerTaskTemplateBuilder,
            SchedulerTaskType,
        },
        set_system_meta_database, system_meta_database,
        workflow::{WorkflowContentType, WorkflowEntityBuilder, WorkflowType},
        Value,
    },
};
use std::borrow::BorrowMut;
use std::{collections::HashMap, thread::sleep, time::Duration};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .init();
    tracing::info!("RRAI 启动...");

    set_system_meta_database(DatabaseDataSource {
        id: 0,
        database_type: DatabaseType::SQLite,
        protocol: ConnectorProtocol::SQLite,
        url: String::from("sqlite:/Users/jinisu/rrg01/rrg01.sqlite"),
        ..Default::default()
    })?;

    let meta_datasource = system_meta_database()?;
    let target = String::from("/Users/jinisu/rrg01/test.zip");

    let option = ServerConfigureOptionBuilder::default()
        .domain(
            DomainConfigureOptionBuilder::default()
                .domains(vec![String::from("_g01_meta")])
                .build()?,
        )
        .scheduler(
            SchedulerConfigureOptionBuilder::default()
                .tasks(vec![
                    String::from("test_task_001"),
                    String::from("test_task_002"),
                ])
                .build()?,
        )
        .build()?;

    let instance =
        g01_builder::exporter::configure::export_server_config(&meta_datasource, &target, option)
            .await?;

    tokio::select! {
        _ = tokio::signal::ctrl_c() => {
            tracing::debug!("{}",instance);
        }
    };
    tracing::info!("RRAI 结束...");
    Ok(())
}
